package com.ruoyi.web.controller.rjgc;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.User;
import com.ruoyi.littleRedBook.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    @ApiOperation("用户注册")
    public AjaxResult register(@ApiParam("用户信息") @RequestBody User user) {
        return userService.register(user);
    }

    @PostMapping("/login")
    @ApiOperation("用户登录")
    public AjaxResult login(@ApiParam("用户名") @RequestParam String username,
                            @ApiParam("密码") @RequestParam String password) {
        return userService.login(username, password);
    }

    @GetMapping("/info")
    @ApiOperation("获取当前用户信息")
    public AjaxResult getUserInfo() {
        return userService.getCurrentUserInfo();
    }

    @PutMapping("/info")
    @ApiOperation("更新用户信息")
    public AjaxResult updateUserInfo(@ApiParam("用户信息") @RequestBody User user) {
        return userService.updateUserInfo(user);
    }

    @PutMapping("/password")
    @ApiOperation("修改密码")
    public AjaxResult updatePassword(@ApiParam("旧密码") @RequestParam String oldPassword,
                                     @ApiParam("新密码") @RequestParam String newPassword) {
        return userService.updatePassword(oldPassword, newPassword);
    }
}
